package org.dant.ant.extension.net.rmi;

import java.rmi.Naming;

import org.dant.ant.extension.tasks.internal.Endpoint;

public final class DistributedAntServer {

    private DistributedAntServer() {
    }
    
    public static void main(String args[]) throws Exception {

        try {
            DistributedAntImpl obj = new DistributedAntImpl();
      
            Endpoint ep = new Endpoint();
            String port = ep.getPort();
            if (args.length == 1) {
                port = args[0];
            }
      
            if (ep.getIp() != null && !"127.0.0.1".equals(ep.getIp())) {
                String ip = ep.constructEndPoint(ep.getIp(), port);
                obj.setFullURL(ip);
                Naming.rebind(ip, obj);
                System.out.println("Running on port " + ip);
            } else if (ep.getHostname() != null && !"localhost".equals(ep.getHostname())) {
                String hostname = ep.constructEndPoint(ep.getHostname(), port);
                obj.setFullURL(hostname);
                Naming.rebind(hostname, obj);
                System.out.println("Running on port " + hostname);
            }

      
        } catch (Exception e) {
            System.out.println("HelloImpl err: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

